package com.zhku.user.controller;

import com.zhku.base.model.PageParams;
import com.zhku.base.model.PageResult;
import com.zhku.base.model.RestResponse;
import com.zhku.user.model.dto.Login;
import com.zhku.user.model.dto.QueryUserParamsDto;
import com.zhku.user.model.dto.UpdateUserAsShopDto;
import com.zhku.user.model.dto.UserDto;
import com.zhku.user.model.po.TtUser;
import com.zhku.user.service.TtUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(value = "用户相关接口",tags = "用户相关接口")
@RestController
public class TtUserController {

    @Autowired
    private TtUserService  ttUserService;

    @ApiOperation("所有用户登录接口")
    @PostMapping("/commonUser/login")
    public RestResponse<TtUser> commonUserLogin(@RequestBody Login login){
        TtUser ttUser = ttUserService.commonLogin(login);
        return RestResponse.success(ttUser);
    }

    @ApiOperation("商家用户登录接口")
    @PostMapping("/shop/login")
    public RestResponse<TtUser> shopLogin(@RequestBody Login login){
        TtUser ttUser = ttUserService.shopLogin(login);
        return RestResponse.success(ttUser);
    }

    @ApiOperation("运营端人员登录接口")
    @PostMapping("/admin/login")
    public RestResponse<TtUser> adminLogin(@RequestBody Login login){
        TtUser ttUser = ttUserService.adminLogin(login);
        return RestResponse.success(ttUser);
    }

    @ApiOperation("用户查询个人信息")
    @GetMapping("/userInfo/{id}")
    public RestResponse<TtUser> getUser(@PathVariable("id") String id){
        TtUser ttUser = ttUserService.getUserByUserId(id);
        return RestResponse.success(ttUser);
    }

    @ApiOperation("修改用户信息")
    @PostMapping("/updateUser")
    public RestResponse<TtUser> updateUser(@RequestBody TtUser ttUser){
        TtUser ttUserNew = ttUserService.updateUser(ttUser);
        return RestResponse.success(ttUserNew);
    }

    @ApiOperation("创建用户")
    @PostMapping("/createUser")
    public RestResponse<TtUser> createUser(@RequestBody UserDto userDto){
        TtUser ttUser = ttUserService.createUser(userDto);
        return RestResponse.success(ttUser);
    }

    @ApiOperation("分页查询所有用户")
    @PostMapping("/userInfo/list")
    public PageResult<TtUser> list(PageParams pageParams, @RequestBody(required = false)QueryUserParamsDto queryUserParamsDto){
        PageResult<TtUser> userPageResult = ttUserService.queryUserList(pageParams,queryUserParamsDto);
        return userPageResult;
    }

    @ApiOperation("运营端禁用用户")
    @PostMapping("/deleteUser/{id}")
    public RestResponse deleteUser(@PathVariable("id") String id){
        ttUserService.deleteUser(id);
        return RestResponse.success();
    }

    @ApiOperation("运营端启用用户")
    @PostMapping("/regainUser/{id}")
    public RestResponse regainUser(@PathVariable("id")String id){
        ttUserService.regainUser(id);
        return RestResponse.success();
    }

    @ApiOperation("分页查询某店铺下有哪些员工")
    @PostMapping("/shop/pageList/{id}")
    public PageResult<TtUser> shopUserPageList(PageParams pageParams,@PathVariable("id") String id){
        PageResult<TtUser> shopUserPageResult = ttUserService.queryShopUserList(pageParams,id);
        return shopUserPageResult;
    }

    @ApiOperation("总查询某店铺下有哪些员工")
    @PostMapping("/shop/list/{id}")
    public List<TtUser> shopUserList(@PathVariable("id") String id){
        List<TtUser> ttUsers = ttUserService.queryShopUserList(id);
        return ttUsers;
    }

    @ApiOperation("将指定的用户所关联的店铺修改为空")
    @PostMapping("/updateUserShop/{id}")
    public RestResponse<TtUser> updateUserShop(@PathVariable("id") String id){
        TtUser ttUser = ttUserService.updateUserShop(id);
        return RestResponse.success(ttUser);
    }

    @ApiOperation("运营端将指定的用户修改为某个店铺下的员工")
    @PostMapping("/updateUserAsShop")
    public RestResponse<TtUser> updateUserAsShop(@RequestBody UpdateUserAsShopDto dto){
        TtUser ttUser = ttUserService.updateUserAsShop(dto);
        return RestResponse.success(ttUser);
    }

}
